package com.ruoyi.stock2.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stock2.domain.SearchFromEsIndustry;
import com.ruoyi.stock2.service.ISearchFromEsIndustryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 从es中查询与模型相似股票的行业Controller
 * 
 * @author ruoyi
 * @date 2021-09-08
 */
@Controller
@RequestMapping("/stock2/industry")
public class SearchFromEsIndustryController extends BaseController
{
    private String prefix = "stock2/industry";

    @Autowired
    private ISearchFromEsIndustryService searchFromEsIndustryService;

    @RequiresPermissions("stock2:industry:view")
    @GetMapping()
    public String industry()
    {
        return prefix + "/industry";
    }

    /**
     * 查询从es中查询与模型相似股票的行业列表
     */
    @RequiresPermissions("stock2:industry:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SearchFromEsIndustry searchFromEsIndustry)
    {
        startPage();
        List<SearchFromEsIndustry> list = searchFromEsIndustryService.selectSearchFromEsIndustryList(searchFromEsIndustry);
        return getDataTable(list);
    }

    /**
     * 导出从es中查询与模型相似股票的行业列表
     */
    @RequiresPermissions("stock2:industry:export")
    @Log(title = "从es中查询与模型相似股票的行业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SearchFromEsIndustry searchFromEsIndustry)
    {
        List<SearchFromEsIndustry> list = searchFromEsIndustryService.selectSearchFromEsIndustryList(searchFromEsIndustry);
        ExcelUtil<SearchFromEsIndustry> util = new ExcelUtil<SearchFromEsIndustry>(SearchFromEsIndustry.class);
        return util.exportExcel(list, "industry");
    }

    /**
     * 新增从es中查询与模型相似股票的行业
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存从es中查询与模型相似股票的行业
     */
    @RequiresPermissions("stock2:industry:add")
    @Log(title = "从es中查询与模型相似股票的行业", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SearchFromEsIndustry searchFromEsIndustry)
    {
        return toAjax(searchFromEsIndustryService.insertSearchFromEsIndustry(searchFromEsIndustry));
    }

    /**
     * 修改从es中查询与模型相似股票的行业
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SearchFromEsIndustry searchFromEsIndustry = searchFromEsIndustryService.selectSearchFromEsIndustryById(id);
        mmap.put("searchFromEsIndustry", searchFromEsIndustry);
        return prefix + "/edit";
    }

    /**
     * 修改保存从es中查询与模型相似股票的行业
     */
    @RequiresPermissions("stock2:industry:edit")
    @Log(title = "从es中查询与模型相似股票的行业", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SearchFromEsIndustry searchFromEsIndustry)
    {
        return toAjax(searchFromEsIndustryService.updateSearchFromEsIndustry(searchFromEsIndustry));
    }

    /**
     * 删除从es中查询与模型相似股票的行业
     */
    @RequiresPermissions("stock2:industry:remove")
    @Log(title = "从es中查询与模型相似股票的行业", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(searchFromEsIndustryService.deleteSearchFromEsIndustryByIds(ids));
    }
}
